﻿using GalaSoft.MvvmLight.Messaging;
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SharpDesktoptool
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            //double x1 = SystemParameters.PrimaryScreenWidth;//得到屏幕整体宽度
            //double y1 = SystemParameters.PrimaryScreenHeight;//得到屏幕整体高度
            //this.Width = x1;//设置窗体宽度
            //this.Height = y1;//设置窗体高度



            this.Loaded += MainWindow_Loaded;
            // Messenger.Default.Register<string>("",(text) => );
            // this.Deactivated += MainWindow_Deactivated;
        }

        private void MainWindow_Deactivated(object sender, EventArgs e)
        {
            this.Activate();
        }

        private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (this.WindowState == WindowState.Minimized)
            {
                this.WindowState = WindowState.Normal;
            }
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr hWnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            //IntPtr hWndProgMan = FindWindow("Progman", "Program Manager");
            //SetParent(hWnd, hWndProgMan);

            //var handle = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            //IntPtr hprog = FindWindowEx(
            //    FindWindowEx(
            //        FindWindow("Progman", "Program Manager"),
            //        IntPtr.Zero, "SHELLDLL_DefView", ""
            //    ),
            //    IntPtr.Zero, "SysListView32", "FolderView"
            //);
            //SetWindowLong(handle, GWL_HWNDPARENT, hprog);

            User32.SetWindowPos(hWnd, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
        }

        [DllImport("user32.dll", SetLastError = true)]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpWindowClass, string lpWindowName);
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
        const int GWL_HWNDPARENT = -8;
        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        private void weather_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void Time_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
    }
}
